package com.ruoyi.web.controller.dormitory;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.dormitory.domain.TbMedicalRecord;
import com.ruoyi.dormitory.service.ITbMedicalRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 看病记录Controller
 *
 * @author ruoyi
 * @date 2023-12-28
 */
@RestController
@RequestMapping("/dormitory/record")
public class TbMedicalRecordController extends BaseController
{
    @Autowired
    private ITbMedicalRecordService tbMedicalRecordService;

    /**
     * 查询看病记录列表
     */
    @PreAuthorize("@ss.hasPermi('dormitory:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbMedicalRecord tbMedicalRecord)
    {
        startPage();
        List<TbMedicalRecord> list = tbMedicalRecordService.selectTbMedicalRecordList(tbMedicalRecord);
        return getDataTable(list);
    }

    /**
     * 导出看病记录列表
     */
    @PreAuthorize("@ss.hasPermi('dormitory:record:export')")
    @Log(title = "看病记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbMedicalRecord tbMedicalRecord)
    {
        List<TbMedicalRecord> list = tbMedicalRecordService.selectTbMedicalRecordList(tbMedicalRecord);
        ExcelUtil<TbMedicalRecord> util = new ExcelUtil<TbMedicalRecord>(TbMedicalRecord.class);
        util.exportExcel(response, list, "看病记录数据");
    }

    /**
     * 获取看病记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('dormitory:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tbMedicalRecordService.selectTbMedicalRecordById(id));
    }

    /**
     * 新增看病记录
     */
    @PreAuthorize("@ss.hasPermi('dormitory:record:add')")
    @Log(title = "看病记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbMedicalRecord tbMedicalRecord)
    {
        return toAjax(tbMedicalRecordService.insertTbMedicalRecord(tbMedicalRecord));
    }

    /**
     * 修改看病记录
     */
    @PreAuthorize("@ss.hasPermi('dormitory:record:edit')")
    @Log(title = "看病记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbMedicalRecord tbMedicalRecord)
    {
        return toAjax(tbMedicalRecordService.updateTbMedicalRecord(tbMedicalRecord));
    }

    /**
     * 删除看病记录
     */
    @PreAuthorize("@ss.hasPermi('dormitory:record:remove')")
    @Log(title = "看病记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tbMedicalRecordService.deleteTbMedicalRecordByIds(ids));
    }
}
